﻿using UnityEngine;
using System.Collections;


namespace VFramework
{

	/// <summary>
	/// 单例,将构造方法私有
	/// </summary>
	public interface ISingleton
	{
		void init ();
		void release ();
	}

	public class Singleton<T> where T : class, ISingleton
	{
		protected static T _instance;
		private static readonly object syslock = new object ();

		public static T getInstance ()
		{
			if (_instance == null) {
				lock (syslock) {
					if (_instance == null) {
						_instance = (T)System.Activator.CreateInstance (typeof (T), true);
						_instance.init ();
					}
				}
			}
			return _instance;
		}
	}

}